﻿$.ajaxSetup({
    type: 'POST',
    async: true,
    cache: false,
    dataType: 'json',
    error: function (a, b, c) {
        console.log('error');
    }
});
define(function (require, exports, module) {
    exports.AjaxAsync = function AjaxAsync(options) {
        return Wind.Async.Task.create(function (t) {

            options.success = function (data, textStatus, jqXHR) {
                data.hasOwnProperty('NotLogin') ? require('login').Show().start() : t.complete('success', data);
            }

            options.error = function (jqXHR, textStatus, errorThrow) {
                t.complete('failure', {
                    jqXHR: jqXHR,
                    textStatus: textStatus,
                    errorThrow: errorThrow
                });
            };

            $.ajax(options);
        });
    };

    exports.Ajax = function (options) {
        var success = options.success;
        options.success = function (result) {
            result.hasOwnProperty('NotLogin') ? require('login')() : (success && success(result));
        };
        $.ajax(options);
    };

    exports.Comet = function () {
        var callee = arguments.callee;
        exports.Ajax({
            url: 'listen.do',
            success: function (result) {
                result.Success && eval(result.Data);
            },
            complete: function () {
                callee();
            }
        });
    };
});